import ctime from '@/components/changeTime.vue'
import {
  share
} from '@/utils/common-api.js'
export default {
  data() {
    return {
      // Core,
      id: '',
      dataObj: {},
      offerCountList: ['待报价', '已报价', '已过期', '已取消'],
      findthecarStatus: false, //上架时间选择状态
      onShelfTime: '', //上架时间
      getOffShelf: false, //下架模态框状态
    }
  },
  onLoad(option) {
    this.id = option.goodsid
    this.getPageDetail()
  },
  components: {
    ctime
  },
  methods: {
    goDetail() {
      uni.navigateTo({
        url: '/pages_Sxy/detailsInqParticipation/detailsInqParticipation'
      })
    },
    async getPageDetail() {
      try {
        const res = await this.$api.findCar.GetCarFindBDetails({
          id: this.id
        })
        console.log(res)
        res.data.facade_pictureList.forEach(item => {
          if (item.inColour) {
            item.inColour.neiColor = item.inColour.colorCoding ? item.inColour.colorCoding.split('/') : []
          }
          if (item.outerColour) {
            item.outerColour.neiColor = item.outerColour.colorCoding ? item.outerColour.colorCoding.split('/') : []
          }
        })
        this.dataObj = res.data

      } catch (e) {
        //TODO handle the exception
      }
    },
    //编辑
    Inquiryedit() {
      uni.navigateTo({
        url: '/pages_findCar/releaseForCar/releaseForCar?type=2&id=' + this.id
      })
    },
    // 跳转我要报价页面
    goMeoffer() {

    },
    returnTime(val) {
      if (val) {
        return val.split('T')[0] + ' ' + val.split('T')[1]
      }
    },
    // 复制
    copy(data) {
      uni.setClipboardData({
        data: data,
        success: function() {
          // console.log('success');
          uni.showToast({
            title: '复制成功',
            icon: 'none'
          })
        }
      })
    },
    // #ifdef APP-PLUS
    share() {
      // 分享方法
      share({
        type: 0,
        summary: '最新求购车源，速戳',
        href: 'https://ztcbs.yzsheng.com/#/pages_findCar/noQuotationForFindCar/noQuotationForFindCar?storeId=' + this.$store
          .state.userInfoDetail.store.storeId + '&type=1&id=' + this.id,
      }, status => {
        if (status) {
          uni.hideToast() // 关闭生成中提示
        } else {
          uni.showToast({
            title: '分享失败',
            duration: 2000
          })
        }
      })
    },
    // #endif

    //我要报价
    // Iwantaquote() {
    //   uni.navigateTo({
    //     url: '/pages_findCar/iWantMakeOffer/iWantMakeOffer'
    //   })
    // },
    // 下架
    Inquiryonshelves() {

      let data = {
        'id': this.id,
        'type': 0,
        'deadline': null
      }
      this.$api.findCar.UpdateState(data).then(res => {
        console.log(res)
        uni.showToast({
          title: '已取消寻车！',
          duration: 2000,
          icon: 'success'
        })
        setTimeout(function() {
          uni.redirectTo({
            url: '/pages_findCar/iFoundTheCar/iFoundTheCar'
          })
        }, 2000)

      }).catch(err => {
        //    uni.showToast({
        // title: '已下架！',
        // duration: 2000,
        // icon: 'success'
        //    })
      })

    },
    // 上架
    confirmFindTheCarStatus(e) {
      var myDate = new Date().toLocaleDateString().split('/')
      this.onShelfTime = ''
      this.findthecarStatus = false
      this.onShelfTime = e.year + '-' + e.month + '-' + e.day

      // 当前时间e
      if (new Date(this.onShelfTime) > new Date(myDate)) {
        // 0下架，1上架
        let data = {
          'id': this.id,
          'type': 1,
          'deadline': this.onShelfTime
        }
        this.$api.findCar.UpdateState(data).then(res => {
          console.log(res)
          uni.showToast({
            title: '上架成功！',
            duration: 2000,
            icon: 'success'
          })
          setTimeout(function() {
            uni.redirectTo({
              url: '/pages_findCar/iFoundTheCar/iFoundTheCar'
            })
          }, 2000)

        }).catch(err => {
          //    uni.showToast({
          // title: '请重试！',
          // duration: 2000,
          // icon: 'none'
          //    })
        })
      } else {
        uni.showToast({
          title: '上架时间不能低于当前时间',
          duration: 2000,
          icon: 'none'
        })
        this.onShelfTime = ''
        return
      }
    },
  }
}
